package com.macro.mall.tiny.common.api;


import com.github.pagehelper.PageInfo;

import java.util.List;

/**
 * 通用分页工具类(对分页数据的封装)
 */
public class CommonPage<T> {
    private Integer pageNum;//当前页码
    private Integer pageSize;//每页显示的记录数
    private Integer totalPage;//总页数
    private Long total;//总记录数
    private List<T> list;//区间数据(例如第五条到第十条)

    /**
     * 将要分页的list转换为PageInfo分页信息,之后就可以获取到分页的数据了
     * @param list
     * @param <T>
     * @return
     */
    public static <T>CommonPage<T> restPage(List<T> list){
        CommonPage<T> page = new CommonPage<T>();
        //用PageInfo对结果进行包装
        PageInfo<T> pageInfo = new PageInfo<T>(list);
        page.setPageNum(pageInfo.getPageNum());
        page.setTotalPage(pageInfo.getPages());
        page.setPageSize(pageInfo.getPageSize());
        page.setTotal(pageInfo.getTotal());
        page.setList(pageInfo.getList());
        return page;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }
}
